defineClass('if', Virtual, function (base) {



    // 检测条件
    defineProperty(this, 'test', {
        
        defaultValue: true,

        onchange: function (value) {

            var template, children;

            if (template = this.__template)
            {
                if ((children = this.__children)[0])
                {
                    changeHidden(children, !value);
                }
                else if (value)
                {
                    buildObjectChildren(this, template);
                }

                invalidateVirtualObject.call(this);
            }
        }
    });



    // 显示或隐藏子项
    function changeHidden(children, hidden) {

        var item, dom;

        for (var i = children.length; i--;)
        {
            if (item = children[i])
            {
                if (item.__virtual && item.__children)
                {
                    changeHidden(item.__children, hidden);
                }
                else if (dom = item.dom)
                {
                    dom.style.display = hidden ? 'none' : '';
                }
            }
        }
    }



    this.__load = function (options) {

        if (options[1])
        {
            loadProperties(this, options[1]);
        }

        if ((this.__template = options[2]) && this.test)
        {
            buildObjectChildren(this, options[2]);
        }
    }



}, function If() {

    this.init();
});
